﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace Hyunhdai_Saigon_Project.uc
{
    public partial class uc_sp_isuzu : System.Web.UI.UserControl
    {
        public PagedDataSource pds1 = new PagedDataSource();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGridIsuzu();
            }
            

        }

        public void manualBindGridIsuzu(String sql)
        {
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["hyundaisaigonConnectionString"].ConnectionString);
            connection.Open();
            SqlDataAdapter da1 = new SqlDataAdapter(sql, connection);
            DataTable dt1 = new DataTable();
            da1.Fill(dt1);
            connection.Close();
            pds1.DataSource = dt1.DefaultView;
            pds1.AllowPaging = true;
            pds1.PageSize = Convert.ToInt16(ddlPageSize1.SelectedValue);
            pds1.CurrentPageIndex = CurrentPage1;
            lnkbtnNext1.Enabled = !pds1.IsLastPage;
            lnkbtnPrevious1.Enabled = !pds1.IsFirstPage;

            dlCountry1.DataSource = pds1;
            dlCountry1.DataBind();

            doPaging1();
        }
        public void BindGridIsuzu()
        {
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["hyundaisaigonConnectionString"].ConnectionString);
            connection.Open();
            string sql1 = "select * from xe where idnsx = 2";
            DataTable dt1 = new DataTable();
            SqlDataAdapter da1 = new SqlDataAdapter(sql1, connection);
            da1.Fill(dt1);
            connection.Close();
            pds1.DataSource = dt1.DefaultView;
            pds1.AllowPaging = true;
            pds1.PageSize = Convert.ToInt16(ddlPageSize1.SelectedValue);
            pds1.CurrentPageIndex = CurrentPage1;
            lnkbtnNext1.Enabled = !pds1.IsLastPage;
            lnkbtnPrevious1.Enabled = !pds1.IsFirstPage;
            dlCountry1.DataSource = pds1;
            dlCountry1.DataBind();
            doPaging1();
        }

        public int CurrentPage1
        {
            get
            {
                if (this.ViewState["CurrentPage1"] == null)
                    return 0;
                else
                    return Convert.ToInt16(this.ViewState["CurrentPage1"].ToString());
            }
            set
            {
                this.ViewState["CurrentPage1"] = value;
            }

        }

        private void doPaging1()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("PageIndex1");
            dt.Columns.Add("PageText1");
            for (int i = 0; i < pds1.PageCount; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = i;
                dr[1] = i + 1;
                dt.Rows.Add(dr);
            }

            dlPaging1.DataSource = dt;
            dlPaging1.DataBind();
        }



        protected void dlPaging_ItemCommand1(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName.Equals("lnkbtnPaging1"))
            {
                CurrentPage1 = Convert.ToInt16(e.CommandArgument.ToString());
                BindGridIsuzu();
            }
        }

        protected void lnkbtnNext_Click1(object sender, EventArgs e)
        {
            CurrentPage1 += 1;
            BindGridIsuzu();
        }



        protected void lnkbtnPrevious_Click1(object sender, EventArgs e)
        {
            CurrentPage1 -= 1;
            BindGridIsuzu();
        }


        protected void ddlPageSize_SelectedIndexChanged1(object sender, EventArgs e)
        {
            CurrentPage1 = 0;
            BindGridIsuzu();
        }


        protected void dlPaging_ItemDataBound1(object sender, DataListItemEventArgs e)
        {
            LinkButton lnkbtnPage = (LinkButton)e.Item.FindControl("lnkbtnPaging1");
            if (lnkbtnPage.CommandArgument.ToString() == CurrentPage1.ToString())
            {
                lnkbtnPage.Enabled = false;
                lnkbtnPage.Font.Bold = true;
            }
        }

        protected void ItemDataBound(object sender, DataListItemEventArgs e)
        {
            Image la2 = (Image)e.Item.FindControl("text");
            Label dgx = (Label)e.Item.FindControl("dgx");
            Label dx = (Label)e.Item.FindControl("dx");
            Label nt = (Label)e.Item.FindControl("nt");
            Label sc = (Label)e.Item.FindControl("sc");
            Label scn = (Label)e.Item.FindControl("scn");
            Label hs = (Label)e.Item.FindControl("hs");
            Label nl = (Label)e.Item.FindControl("nl");
            Label htnl = (Label)e.Item.FindControl("htnl");
            Label ttnl = (Label)e.Item.FindControl("ttnl");

            string demo = "<table BORDER=1 CELLPADDING=3 CELLSPACING=1 RULES=ROWS RULES=COLS FRAME=BOX  class = tooltip>" + "<tr><td width = 180px>Dòng Xe:</td><td width:150px>" + dgx.Text + "</td></tr><tr><td>Đời Xe:</td><td>" + dx.Text + "</td></tr><tr><td>Ngoại Thất:</td><td>" + nt.Text + "</td></tr><tr><td>Số Cửa:</td><td>" + sc.Text + "</td></tr><tr><td>Số Chỗ Ngồi:</td><td>" + scn.Text + "</td></tr><tr><td>Hộp Số:</td><td>" + hs.Text + "</td></tr><tr><td>Nhiêu Liệu:</td><td>" + nl.Text + "</td></tr><tr><td>Hệ Thống Nhiên Liệu:</td><td>" + htnl.Text + "</td></tr><tr><td>Tiêu Thụ Nhiên Liệu:</td><td>" + ttnl.Text + "</td></tr></table>";


            String str = dgx.Text + "<br />" + dx.Text + "<br />" + nt.Text + "<br />" + sc.Text + "<br />" + scn.Text + "<br />" + hs.Text + "<br />" + nl.Text + "<br />" + htnl.Text + "<br />" + ttnl.Text;
            la2.Attributes.Add("onMouseover", "ddrivetip(' " + demo + " ', 298,'white');");
            la2.Attributes.Add("onmouseout", "hideddrivetip();");

        }
        protected string check(string s)
        {
            if (s.Contains("http://") || s.Contains("www."))
            {
                return Eval("imgURL").ToString();
            }
            else
            {
                return "/" + Eval("imgURL").ToString();
            }

        }

    }
}